package mycharstream;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Arrays;

public class Test03 {
    public static void main(String[] args) throws IOException {
        FileReader fr = new FileReader("csb.txt");
        int ch;
        StringBuilder sb = new StringBuilder();
        while ((ch = fr.read()) != -1){
            sb.append((char) ch);
        }
        fr.close();
        System.out.println(sb);
        Integer[] array = Arrays.stream(sb.toString().
                        split("-")).
                map(Integer::parseInt).
                sorted().
                toArray(Integer[]::new);
        System.out.println(Arrays.toString(array));
        String replace = Arrays.toString(array).replace(", ", "-");
        String result = replace.substring(1, replace.length() - 1);
        System.out.println(result);
        FileWriter fw = new FileWriter("csb.txt");
        fw.write(result);
        fw.close();
    }
}
